package io.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.Test;

/**
 * 字符缓冲流
 * @author Administrator
 *
 */
public class BufferedCharIODemo {

	/**
	 * 字符缓冲输入流
	 * @throws IOException 
	 */
	@Test
	public void demo() throws IOException {
		
		// 创建
		BufferedReader bufferedReader = new BufferedReader(new FileReader("F:\\a.txt"));
//		BufferedReader bufferedReader = new BufferedReader(in, sz); // in:字符输入流  	sz:缓冲区域大小
		
		// 读取
//		bufferedReader.read();  int 
//		bufferedReader.read(char[]);  int char[]
//		bufferedReader.read(cbuf, off, len); int char[]
		
		String content = bufferedReader.readLine(); // 返回String
		while(content != null) {
			System.out.println(content);
			content = bufferedReader.readLine();
		}
		
		// 关闭流
		bufferedReader.close();
	}
	
	/**
	 * 缓冲字符输出流
	 * @throws IOException 
	 */
	@Test
	public void demo2() throws IOException {
		// 创建
		BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("F:\\a.txt"));
//		BufferedWriter bufferedWriter = new BufferedWriter(out, size);
		
		// 输出
		bufferedWriter.write("xxxxxxx");
		bufferedWriter.newLine(); // 重启一行
		bufferedWriter.write("xxxxxxx");
		
		// 清除缓存
		bufferedWriter.flush();

		// 关闭
		bufferedWriter.close();
	}
	
	
	
	
	
	
	
	
	
	
	
}
